<template>
  <view class="about-container">
    <!-- 页面标题 -->
    <view class="page-title">关于我们</view>

    <!-- 内容区域 -->
    <view class="content-container">
      <!-- 加载状态 -->
      <view class="loading-container" v-if="loading">
        <uni-loading type="spinner" size="24"></uni-loading>
        <text class="loading-text">加载中...</text>
      </view>

      <!-- 错误提示 -->
      <view class="error-container" v-else-if="error">
        <text class="error-text">{{ errorMsg }}</text>
        <button class="retry-btn" @tap="getAboutData">重试</button>
      </view>

      <!-- 关于我们内容 -->
      <view class="about-content" v-else>
        <!-- 联系电话 -->
        <view class="contact-info" v-if="aboutData.phone">
          <text class="contact-label">联系电话：</text>
          <text class="contact-value">{{ aboutData.phone }}</text>
          <button class="call-btn" @tap="makePhoneCall">
            <image class="call-icon" src="/static/androidImg/icon_customer.png" mode="aspectFit"></image>
          </button>
        </view>

        <!-- 公司介绍 -->
        <view class="company-intro">
          <rich-text :nodes="aboutData.content"></rich-text>
        </view>
      </view>
    </view>

    <!-- 版权信息 -->
    <view class="copyright">
      <text>© 2023 郑州尚厨餐饮配送服务公司 版权所有</text>
    </view>
  </view>
</template>

<script>
import api from '../../api/request.js';

export default {
  data() {
    return {
      loading: true,
      error: false,
      errorMsg: '',
      aboutData: {
        phone: '',
        content: ''
      }
    };
  },
  onLoad() {
    this.getAboutData();
  },
  methods: {
    // 获取关于我们数据
    getAboutData() {
      this.loading = true;
      this.error = false;

      api.getAboutUs()
        .then((res) => {
          this.loading = false;
          if (res.code == 1 && res.data) {
            this.aboutData = res.data;
          } else {
            this.error = true;
            this.errorMsg = res.msg || '获取数据失败';
          }
        })
        .catch((err) => {
          this.loading = false;
          this.error = true;
          this.errorMsg = '网络请求失败，请稍后重试';
          console.error('获取关于我们数据失败', err);
        });
    },

    // 拨打电话
    makePhoneCall() {
      if (this.aboutData.phone) {
        uni.makePhoneCall({
          phoneNumber: this.aboutData.phone
        });
      }
    }
  }
};
</script>

<style lang="scss">
.about-container {
  padding: 20rpx;
  background-color: #f5f5f5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  padding: 20rpx 0;
  text-align: center;
  border-bottom: 1rpx solid #eee;
  margin-bottom: 30rpx;
}

.content-container {
  flex: 1;
  background-color: #fff;
  border-radius: 16rpx;
  padding: 30rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 400rpx;
}

.loading-text {
  font-size: 28rpx;
  color: #999;
  margin-top: 20rpx;
}

.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 400rpx;
}

.error-text {
  font-size: 28rpx;
  color: #f00;
  margin-bottom: 20rpx;
}

.retry-btn {
  background-color: #ff6b00;
  color: #fff;
  font-size: 28rpx;
  padding: 0 40rpx;
  border-radius: 45rpx;
}

.about-content {
  padding: 20rpx 0;
}

.contact-info {
  display: flex;
  align-items: center;
  padding: 20rpx 0;
  border-bottom: 1rpx solid #eee;
  margin-bottom: 30rpx;
}

.contact-label {
  font-size: 28rpx;
  color: #666;
  margin-right: 10rpx;
}

.contact-value {
  font-size: 28rpx;
  color: #333;
  flex: 1;
}

.call-btn {
  width: 60rpx;
  height: 60rpx;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: 10rpx;
}

.call-icon {
  width: 36rpx;
  height: 36rpx;
}

.company-intro {
  font-size: 28rpx;
  color: #333;
  line-height: 1.6;
}

.company-intro p {
  margin-bottom: 20rpx;
}

.copyright {
  font-size: 24rpx;
  color: #999;
  text-align: center;
  padding: 30rpx 0;
  margin-top: 30rpx;
}
</style>